package com.djzz.app.wdy.base;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.djzz.app.wdy.definations.keys.IntentKeys;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 活动基类
 * Created by 郝赫 on 2017/8/30.
 */

public abstract class BaseActivity extends AppCompatActivity {

    protected Unbinder unbinder;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(setLayoutId());
        unbinder = ButterKnife.bind(this);
        init();
    }

    protected abstract int setLayoutId();
    protected abstract void init();

    protected void redirectTo(Class<? extends Activity> activity){
        redirectTo(activity, false);
    }

    protected void redirectTo(Class<? extends Activity> activity, boolean isFinish){

        redirectTo(activity, isFinish, null);
    }

    protected void redirectTo(Class<? extends Activity> activity, boolean isFinish, Bundle bundle){
        Intent intent = new Intent();
        intent.setClass(this, activity);
        if(bundle != null){
            intent.putExtra(IntentKeys.BUNDLE, bundle);
        }

        startActivity(intent);

        if(isFinish){
            this.finish();
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }
}
